import dayjs from 'dayjs'
import {
    getCollectedList, // 已领取薪资
} from '../../api/get-paid'

Page({
    data: {
        wagesList: [],
        tabflag: 0,
        data: '',
    },
    onLoad() {
        this.getCollectedList(dayjs().format('YYYY-MM'))
    },
    changetab(e) {
        console.log(e)
        this.setData({
            tabflag: e.currentTarget.dataset.i
        })
        this.getCollectedList(this.data.data, this.data.tabflag === 0 ? '' : this.data.tabflag === 1 ? 2 : 1)
    },
    goPath(event) {
        console.log(event)
        let gid = event.currentTarget.dataset.id
        let cid = event.currentTarget.dataset.applyid
        if (event.currentTarget.dataset.type === 0) {
            wx.navigateTo({
                url: '/pages/salary-list-details/salary-list-details?id=' + gid
            })
        } else {
            wx.navigateTo({
                url: '/packageAdvance/pages/advance-detail/advance-detail?id=' + cid
            })
        }
    },
    async getCollectedList(date = '', type = '') {
        const wagesList = await getCollectedList({
            month: date,
            salaryComeForm: type
        })
        console.log(wagesList, 'wagesListwagesListwagesList')
        this.setData({
            wagesList
        })
        let length = 0
        for (let index in wagesList) {
            length += 1
            wagesList[index].list.forEach((item2, index2) => {
                this.setData({
                    ['wagesList.' + index + '.list[' + index2 + '].createTime']: item2.createTime.split(/[ ]+/)[0]
                })
            })
        }
        this.setData({
            ['wagesList.length']: length
        })
    },
    onMonthChange(event) {
        this.setData({
            data: event.detail.value,
        })
        this.getCollectedList(this.data.data, this.data.tabflag === 0 ? '' : this.data.tabflag === 1 ? 2 : 1)
    }
})